﻿Imports System.Data.SqlClient
Public Class changmoney


    Private Sub changmoney_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        condb()
        condb()
        grdmoney.Rows.Clear()
        Dim cmd As New SqlCommand("select * from changmoney", cn)
        Dim rd = cmd.ExecuteReader
        While rd.Read = True
            grdmoney.Rows.Add(rd(0), rd(1), rd(2))
        End While
        rd.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        Dim code As Double
        For i = 0 To grdmoney.Rows.Count - 1
            code = grdmoney.Rows(i).Cells(0).Value
            Dim cmd As New SqlCommand("Update changmoney set Rial='" & txtrial.Text & "' where code='" & code & "'", cn)
            cmd.ExecuteNonQuery()
            changmoney_Load(sender, e)
        Next
    End Sub

    Private Sub grdmoney_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdmoney.SelectionChanged
        If Me.grdmoney.SelectedRows.Count = 0 Then
            Exit Sub
        End If
        Dim row As DataGridViewRow = Me.grdmoney.SelectedRows(0)
        txtrial.Text = row.Cells("rial").Value
    End Sub
End Class